package com.adv.io;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 5：通过控制台输入字符，如果输入的是quit,则退出,否则继续输入;把输入的字符写入文件保存,
 * 每输入一次换行，并在每行之前加上写入的时间，用hh:mm:ss的格式,时间后面加上一个空格 类似 11:34:21 hello 11:34:27 how
 * do you do?
 * 
 * @author zhaoyang
 *
 */
public class IO_Work05 {

	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		String str;
		BufferedWriter bw = new BufferedWriter(new FileWriter("Date.txt"));
		while (true) {
			System.out.print("请输入字符：");
			str = input.next();
			SimpleDateFormat sf = new SimpleDateFormat("hh:mm:ss");
			bw.append(sf.format(new Date()) + " " + str + "\r\n");
			if (str.equals("quit")) {
				bw.close();
				break;
			}
		}
		System.out.println(">>>>>>>>>>>>>>>");
		BufferedReader br = new BufferedReader(new FileReader("Date.txt"));
		String str2 = null;
		while ((str2 = br.readLine()) != null) {
			System.out.println(str2);
		}
		br.close();

	}

}
